//
//  YWDailyReportDetailCell.m
//  maintain
//
//  Created by 烟雨云渊 on 2017/6/6.
//  Copyright © 2017年 ewin. All rights reserved.
//

#import "YWDailyReportDetailCell.h"
#import "YWMacro.h"
#import "Masonry.h"
#import "UIColor+CustomColors.h"
#import "YWDailyReport.h"

@interface YWDailyReportDetailCell()
@property (nonatomic, strong) UIImageView * logoView;
@property (nonatomic, strong) UILabel * funtionLb;
@property (nonatomic, strong) UILabel * missionCountLb;
@property (nonatomic, strong) UILabel * missionLb;
@property (nonatomic, strong) UILabel * tempLb;
@property (nonatomic, strong) UILabel * tempCountLb;
@property (nonatomic, strong) UILabel * unfinishLb;
@property (nonatomic, strong) UILabel * unfinishCountLb;
@property (nonatomic, strong) UILabel * finishLb;
@property (nonatomic, strong) UILabel * finishCountLb;
@property (nonatomic, strong) UILabel * finishRateLb;
@property (nonatomic, strong) UILabel * finisnRateCountLb;
@end

@implementation YWDailyReportDetailCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [UIScreen mainScreen].scale;
        [self setUpSubviews];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setDailyReport:(YWDailyReport *)dailyReport{
    _dailyReport = dailyReport;
    if (_dailyReport.maintenanceTypeId == YWMaintenanceTypeReportTrouble) {
        _logoView.image = [UIImage imageNamed:@"profile_postTrouble"];
        _funtionLb.text = NSLocalizedString(@"postTrouble", nil);
        NSString * totalCount= [NSString stringWithFormat:@"%ld",(long)_dailyReport.total];
        _missionCountLb.text = totalCount;
        _missionLb.text = @"今日报障";
        NSString * unDistributeCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.unDistributeCount];
        _tempCountLb.text = unDistributeCount;
        _tempLb.text = @"未分配";
        NSString * unFinishCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.unFinishCount];
        _unfinishCountLb.text = unFinishCount;
        _unfinishLb.text = @"未完成";
        NSString * finistCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.finishCount];
        _finishCountLb.text = finistCount;
        _finishLb.text = @"已完成";
        NSString * rateCount = [NSString stringWithFormat:@"%d%%",(_dailyReport.finishCount/_dailyReport.total)*100];
        _finisnRateCountLb.text = rateCount;
        _finishRateLb.text = @"完成率";
    }else if (_dailyReport.maintenanceTypeId == YWMaintenanceTypeTrouble){
        _logoView.image = [UIImage imageNamed:@"profile_repair"];
        _funtionLb.text = NSLocalizedString(@"trouble", nil);
        NSString * totalCount= [NSString stringWithFormat:@"%ld",(long)_dailyReport.total];
        _missionCountLb.text = totalCount;
        _missionLb.text = @"任务总数";
        NSString * unDistributeCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.tempCount];
        _tempCountLb.text = unDistributeCount;
        _tempLb.text = @"临时维修";
        NSString * unFinishCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.unFinishCount];
        _unfinishCountLb.text = unFinishCount;
        _unfinishLb.text = @"未完成";
        NSString * finistCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.finishCount];
        _finishCountLb.text = finistCount;
        _finishLb.text = @"已完成";
        NSString * rateCount = [NSString stringWithFormat:@"%d%%",(_dailyReport.finishCount/_dailyReport.total)*100];
        _finisnRateCountLb.text = rateCount;
        _finishRateLb.text = @"完成率";
    }else if (_dailyReport.maintenanceTypeId == YWMaintenanceTypeDetection){
        _logoView.image = [UIImage imageNamed:@"profile_detection"];
        _funtionLb.text = NSLocalizedString(@"detection", nil);
        NSString * totalCount= [NSString stringWithFormat:@"%ld",(long)_dailyReport.total];
        _missionCountLb.text = totalCount;
        _missionLb.text = @"任务总数";
        NSString * unDistributeCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.tempCount];
        _tempCountLb.text = unDistributeCount;
        _tempLb.text = @"临时检测";
        NSString * unFinishCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.unFinishCount];
        _unfinishCountLb.text = unFinishCount;
        _unfinishLb.text = @"未完成";
        NSString * finistCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.finishCount];
        _finishCountLb.text = finistCount;
        _finishLb.text = @"已完成";
        NSString * rateCount = [NSString stringWithFormat:@"%d%%",(_dailyReport.finishCount/_dailyReport.total)*100];
        _finisnRateCountLb.text = rateCount;
        _finishRateLb.text = @"完成率";
    }else if (_dailyReport.maintenanceTypeId == YWMaintenanceTypeKeepWatch){
        _logoView.image = [UIImage imageNamed:@"patroling"];
        _funtionLb.text = NSLocalizedString(@"keepWatch", nil);
        NSString * totalCount= [NSString stringWithFormat:@"%ld",(long)_dailyReport.total];
        _missionCountLb.text = totalCount;
        _missionLb.text = @"任务总数";
        NSString * unDistributeCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.tempCount];
        _tempCountLb.text = unDistributeCount;
        _tempLb.text = @"临时巡更";
        NSString * unFinishCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.unFinishCount];
        _unfinishCountLb.text = unFinishCount;
        _unfinishLb.text = @"未完成";
        NSString * finistCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.finishCount];
        _finishCountLb.text = finistCount;
        _finishLb.text = @"已完成";
        NSString * rateCount = [NSString stringWithFormat:@"%d%%",(_dailyReport.finishCount/_dailyReport.total)*100];
        _finishRateLb.text = @"完成率";
        _finisnRateCountLb.text = rateCount;
    }else if (_dailyReport.maintenanceTypeId == YWMaintenanceTypePatrol){
        _logoView.image = [UIImage imageNamed:@"profile_patrol"];
        _funtionLb.text = NSLocalizedString(@"inspection", nil);
        NSString * totalCount= [NSString stringWithFormat:@"%ld",(long)_dailyReport.total];
        _missionCountLb.text = totalCount;
        _missionLb.text = @"任务总数";
        NSString * unDistributeCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.tempCount];
        _tempCountLb.text = unDistributeCount;
        _tempLb.text = @"临时巡查";
        NSString * unFinishCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.unFinishCount];
        _unfinishCountLb.text = unFinishCount;
        _unfinishLb.text = @"未完成";
        NSString * finistCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.finishCount];
        _finishCountLb.text = finistCount;
        _finishLb.text = @"已完成";
        NSString * rateCount = [NSString stringWithFormat:@"%d%%",(_dailyReport.finishCount/_dailyReport.total)*100];
        _finishRateLb.text = @"完成率";
        _finisnRateCountLb.text = rateCount;
    }else if (_dailyReport.maintenanceTypeId == YWMaintenanceTypeUpkeep){
        _logoView.image = [UIImage imageNamed:@"profile_upkeep"];
        _funtionLb.text = NSLocalizedString(@"upkeep", nil);
        NSString * totalCount= [NSString stringWithFormat:@"%ld",(long)_dailyReport.total];
        _missionCountLb.text = totalCount;
        _missionLb.text = @"任务总数";
        NSString * unDistributeCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.tempCount];
        _tempCountLb.text = unDistributeCount;
        _tempLb.text = @"临时保养";
        NSString * unFinishCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.unFinishCount];
        _unfinishCountLb.text = unFinishCount;
        _unfinishLb.text = @"未完成";
        NSString * finistCount = [NSString stringWithFormat:@"%ld",(long)_dailyReport.finishCount];
        _finishCountLb.text = finistCount;
        _finishLb.text = @"已完成";
        NSString * rateCount = [NSString stringWithFormat:@"%d%%",(_dailyReport.finishCount/_dailyReport.total)*100];
        _finishRateLb.text = @"完成率";
        _finisnRateCountLb.text = rateCount;
    }
}

- (void)setUpSubviews{
    UIView *superView = self.contentView;
    [self.logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView).offset(6);
        make.left.mas_equalTo(superView).offset(10);
        make.width.and.height.mas_equalTo(32);
    }];
    [self.funtionLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView).mas_offset(12);
        make.left.mas_equalTo(_logoView.mas_right).offset(kMarginW);
        make.right.mas_equalTo(superView).mas_offset(-6);
        make.height.mas_equalTo(kLabelH);
    }];

    [self.missionCountLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView).offset(44);
        make.left.mas_equalTo(superView).offset(kMarginW);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
    }];
    [self.missionLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_missionCountLb.mas_bottom).offset(6);
        make.left.mas_equalTo(superView).offset(kMarginW);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
        make.bottom.mas_equalTo(superView).offset(-6);
    }];
    [self.tempCountLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_missionCountLb);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
        make.left.mas_equalTo(_missionCountLb.mas_right);
    }];
    [self.tempLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_missionLb);
        make.left.mas_equalTo(_missionLb.mas_right);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
        make.bottom.mas_equalTo(superView).offset(-6);
    }];
    [self.unfinishCountLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_missionCountLb);
        make.left.mas_equalTo(_tempCountLb.mas_right);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
    }];
    [self.unfinishLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_missionLb);
        make.left.mas_equalTo(_tempLb.mas_right);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
        make.bottom.mas_equalTo(superView).offset(-6);
    }];
    [self.finishCountLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_missionCountLb);
        make.left.mas_equalTo(_unfinishCountLb.mas_right);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
    }];
    [self.finishLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_missionLb);
        make.left.mas_equalTo(_unfinishLb.mas_right);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
        make.bottom.mas_equalTo(superView).offset(-6);
    }];
    [self.finisnRateCountLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_missionCountLb);
        make.left.mas_equalTo(_finishCountLb.mas_right);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
    }];
    [self.finishRateLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_missionLb);
        make.left.mas_equalTo(_finishLb.mas_right);
        make.width.mas_equalTo((SCREEN_WIDTH-20)/5);
        make.bottom.mas_equalTo(superView).offset(-6);
    }];
}

- (UIImageView*)logoView{
    if (!_logoView) {
        UIImageView * logoView = [[UIImageView alloc] init];
        logoView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:logoView];
        _logoView = logoView;
    }
    return _logoView;
}

- (UILabel *)funtionLb{
    if (!_funtionLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = KTitleFont;
        label.textColor = [UIColor blackColor];
        _funtionLb = label;
        [self.contentView addSubview:_funtionLb];
    }
    return _funtionLb;
}

- (UILabel *)missionCountLb{
    if (!_missionCountLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textColor = [UIColor blackColor];
        label.textAlignment = NSTextAlignmentCenter;
        _missionCountLb = label;
        [self.contentView addSubview:_missionCountLb];
    }
    return _missionCountLb;
}

- (UILabel *)missionLb{
    if (!_missionLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor customTextGrayColor];
        _missionLb = label;
        [self.contentView addSubview:_missionLb];
    }
    return _missionLb;
}

- (UILabel *)tempLb{
    if (!_tempLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor customTextGrayColor];
        _tempLb = label;
        [self.contentView addSubview:_tempLb];
    }
    return _tempLb;
}

- (UILabel *)tempCountLb{
    if (!_tempCountLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor blackColor];
        _tempCountLb = label;
        [self.contentView addSubview:_tempCountLb];
    }
    return _tempCountLb;
}

- (UILabel *)unfinishLb{
    if (!_unfinishLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor customTextGrayColor];
        _unfinishLb = label;
        [self.contentView addSubview:_unfinishLb];
    }
    return _unfinishLb;
}

- (UILabel *)unfinishCountLb{
    if (!_unfinishCountLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor blackColor];
        _unfinishCountLb = label;
        [self.contentView addSubview:_unfinishCountLb];
    }
    return _unfinishCountLb;
}

- (UILabel *)finishLb{
    if (!_finishLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor customTextGrayColor];
        _finishLb = label;
        [self.contentView addSubview:_finishLb];
    }
    return _finishLb;
}

- (UILabel *)finishCountLb{
    if (!_finishCountLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor blackColor];
        _finishCountLb = label;
        [self.contentView addSubview:_finishCountLb];
    }
    return _finishCountLb;
}

- (UILabel *)finishRateLb{
    if (!_finishRateLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor customTextGrayColor];
        _finishRateLb = label;
        [self.contentView addSubview:_finishRateLb];
    }
    return _finishRateLb;
}

- (UILabel *)finisnRateCountLb{
    if (!_finisnRateCountLb) {
        UILabel *label = [[UILabel alloc] init];
        label.font = kContentFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor blackColor];
        _finisnRateCountLb = label;
        [self.contentView addSubview:_finisnRateCountLb];
    }
    return _finisnRateCountLb;
}

@end
